/*
 * @Author: Turump 
 * @Date: 2021-04-25 20:33:32 
 * @Last Modified by: Turump
 * @Last Modified time: 2021-04-26 19:57:14
 */

import { TweenType } from "../../misc/TweenType";
import ActionBaseTask from "./ActionBaseTask";

const { ccclass, property, menu } = cc._decorator;

@ccclass
@menu("动作任务/MoveBy")
export default class MoveByTask extends ActionBaseTask {

    @property({ displayName: "MoveBy参数" })
    moveByParam: cc.Vec2 = cc.v2(0, 0);

    @property()
    reverse = false;

    @property({ displayName: "循环次数", tooltip: "无限循环就把数字设大一点", visible() { return this.reverse } })
    repeatTime = 1;

    getAction() {
        let tween: cc.Tween = null;
        if (this.reverse == false) {
            tween = cc.tween(this.node)
                .then(this.getPlayAudioTween())
                .by(this.actionDuration,
                    { position: cc.v3(this.moveByParam) }, { easing: Object.keys(TweenType)[this.easeType] })
        } else {
            tween = cc.tween(this.node)
                .repeat(this.repeatTime,
                    cc.tween(this.node)
                        .then(this.getPlayAudioTween())
                        .by(this.actionDuration, { position: cc.v3(this.moveByParam) }, { easing: Object.keys(TweenType)[this.easeType] })
                        .by(this.actionDuration, { position: cc.v3(this.moveByParam.mul(-1)) }, { easing: Object.keys(TweenType)[this.easeType] })
                )
        }

        return tween;
    }

}
